/**
 * 
 */
package com.flying.dcss.userpermissions.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.flying.dcss.app.SessionName;
import com.flying.dcss.userpermissions.bo.impl.DcssUser;
import com.flying.dcss.userpermissions.bo.impl.DcssUserInfo;
import com.flying.dcss.userpermissions.service.impl.UserInfoService;
import com.flying.dcss.userpermissions.service.impl.UserService;
import com.opensymphony.xwork2.ActionSupport;

// TODO: Auto-generated Javadoc
/**
 * The Class ProfileQueryAction.
 * 
 * @author EvanHong
 */
public class ProfileQueryAction extends ActionSupport {

	/** The user service. */
	private UserService userService;

	/** The user info service. */
	private UserInfoService userInfoService;

	/**
	 * Sets the user service.
	 * 
	 * @param userService
	 *            the new user service
	 */
	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	/**
	 * Sets the user info service.
	 * 
	 * @param userInfoService
	 *            the new user info service
	 */
	public void setUserInfoService(UserInfoService userInfoService) {
		this.userInfoService = userInfoService;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		// Get user email.
		DcssUser user = (DcssUser) ServletActionContext.getRequest()
				.getSession().getAttribute(SessionName.UserSession);

		String userEmail = user.getEmail();

		// Get real user from Database.
		DcssUser realUser = userService.getUserByEmail(userEmail);
		// Get userInfo.
		DcssUserInfo userInfo = userInfoService.getUserInfoByUserId(realUser
				.getId());

		// Write session.
		ServletActionContext.getRequest().setAttribute(
				SessionName.ProfileQueryUserSession, realUser);
		ServletActionContext.getRequest().setAttribute(
				SessionName.ProfileQueryUserInfoSession, userInfo);

		return this.SUCCESS;
	}
}